﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Calaulation
{
    public partial class Form1 : Form
    {
        int score = 0;//分数
        int time=10;//时间
        int questionnumber = 10;//题目数量
        public Form1()
        {
            InitializeComponent();                        
        }
        //开始按钮
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            UpdateQuestion();
        }
        //确定按钮
        private void button2_Click(object sender, EventArgs e)
        {
            if (label2.Text=="+")
            {
                if(Convert.ToInt32(textBox1.Text)== Convert.ToInt32(textBox2.Text)+ Convert.ToInt32(textBox3.Text))
                {
                    MessageBox.Show("正确");
                    score = score+10;
                }
                else
                {
                    MessageBox.Show("错误");
                }

            }
            else if (label2.Text == "—")
            {
                if (Convert.ToInt32(textBox1.Text) == Convert.ToInt32(textBox2.Text) - Convert.ToInt32(textBox3.Text))
                {
                    MessageBox.Show("正确");
                    score = score+10;
                }
                else
                {
                    MessageBox.Show("错误");
                }
            }
            label6.Text = Convert.ToString(score);
            if (questionnumber <= 0)
            {
                timer1.Enabled = false;
                MessageBox.Show("测试结束，你的分数是" + score);
                return;
            }
            UpdateQuestion();
            
        }
        //计时器
        private void timer1_Tick(object sender, EventArgs e)
        {
            time--;
            label3.Text = Convert.ToString(time);
            
            if(time<=0)
            {
                time = 10;
                MessageBox.Show("超时！");                
                UpdateQuestion();
            }
        }
        //更新题目
        public void UpdateQuestion()
        {
            time = 10;
            Random ra1 = new Random();
            Random ra2 = new Random();
            Random ra3 = new Random();
            textBox2.Text = Convert.ToString(ra1.Next(1, 100));
            if (ra2.Next(1, 3).Equals(1))
            {
                label2.Text = "+";
            }
            else
            {
                label2.Text = "—";
            }
            textBox3.Text = Convert.ToString(ra3.Next(1, 100));
            questionnumber--;
        }
    }
}
